const http = require('http');
const path = require('path');
const readStaticFile = require('./readFileStatic');

http.createServer(async (req, res) => {
    // 获取请求路径
    let urlString = req.url;

    // 拼接静态资源路径
    let filePathName = path.join(__dirname, '/public', urlString);
    // 读取静态资源文件
    let { data, mimeType } = await readStaticFile(filePathName);
    res.writeHead(200, {
        'content-type': `${mimeType}; charset=utf-8`
    })
    res.write(data);
    res.end();
}).listen(8080, () => {
    console.log('localhost:8080');
})